#include <Windows.h>
#include <D3D9.h>

#include "../Primitives/IPrimitive.h"


class ILoop;
class ZBuffer;

class DxApp:public IPixelDrawer{
public:
	DxApp(int width,int height);
	~DxApp(){};
	static DxApp* create(HINSTANCE instance,int width = 600,int height = 600);
public:
	inline HWND getWnd(){return _wnd;};
	void setLooper(ILoop* looper);

	virtual void drawPixel(int x,int y,COLOR color);
	void clearBuffer();
	void flushBuffer();

	void dealMsg();
	virtual int getW(){return _w;};
	virtual int getH(){return _h;};
	virtual bool testZBuffer(int x,int y,float z) ;
	virtual void setCullFrontFace(eFrontFace frontFace){_cullFront=frontFace;};
	virtual eFrontFace getCullFrontFace(){return _cullFront;};
private:
	void initWnd();
	void initD3D();
	void initConsole();
	void initZBuffer();
	int _w,_h;
	static HINSTANCE _instance;
	HWND _wnd;
	IDirect3DDevice9* _device;
	IDirect3DSurface9* _surface;
	ILoop* _looper;
	D3DLOCKED_RECT lr;

	ZBuffer* _zBuffer;
	eFrontFace _cullFront;
};